package com.acidu.blogs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.acidu.blogs.domain.AddAciduBlogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.acidu.blogs.domain.AciduBlog;
import com.acidu.blogs.service.IAciduBlogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博文管理Controller
 * 
 * @author xiaofeng
 * @date 2025-01-21
 */
@Api("博文管理")
@RestController
@RequestMapping("/acidu-blogs/blog")
public class AciduBlogController extends BaseController
{
    @Autowired
    private IAciduBlogService aciduBlogService;

    /**
     * 查询博文管理列表
     */
    @ApiOperation("查询博文列表")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:list')")
    @GetMapping("/list")
    public TableDataInfo list(AciduBlog aciduBlog)
    {
        startPage();
        List<AciduBlog> list = aciduBlogService.selectAciduBlogList(aciduBlog);
        return getDataTable(list);
    }

    /**
     * 导出博文管理列表
     */
    @ApiOperation("导出博文列表")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:export')")
    @Log(title = "博文管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AciduBlog aciduBlog)
    {
        List<AciduBlog> list = aciduBlogService.selectAciduBlogList(aciduBlog);
        ExcelUtil<AciduBlog> util = new ExcelUtil<AciduBlog>(AciduBlog.class);
        util.exportExcel(response, list, "博文管理数据");
    }

    /**
     * 获取博文管理详细信息
     */
    @ApiOperation("获取博文详细信息")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aciduBlogService.selectAciduBlogById(id));
    }

    /**
     * 新增博文管理
     */
    @ApiOperation("新增博文")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:add')")
    @Log(title = "博文管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddAciduBlogVo aciduBlog)
    {
        aciduBlog.setCreateBy(getUsername());
        return toAjax(aciduBlogService.insertAciduBlog(aciduBlog));
    }

    /**
     * 修改博文管理
     */
    @ApiOperation("修改博文")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:edit')")
    @Log(title = "博文管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddAciduBlogVo aciduBlog)
    {
        aciduBlog.setUpdateBy(getUsername());
        return toAjax(aciduBlogService.updateAciduBlog(aciduBlog));
    }

    /**
     * 删除博文管理
     */
    @ApiOperation("删除博文")
    @PreAuthorize("@ss.hasPermi('acidu-blogs:blog:remove')")
    @Log(title = "博文管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(aciduBlogService.deleteAciduBlogByIds(ids));
    }
}
